#include <bits/stdc++.h>
using namespace std;
int t,n;
int a[200005],c[200005];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--)
    {
        cin>>n;
        int maxn=0;
        memset(a,0,sizeof a);
        memset(c,0,sizeof c);
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            c[a[i]]++;
        }
        for(int i=1;i<=n;i++)
        {
            if(c[a[i]]>1)
            {
                maxn+=(c[a[i]]-1)*a[i];
                c[a[i]]=0;
            }
        }
        cout<<maxn<<"\n";
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
